package cn.autumnorange.app.scheduletask.consumer.queue;//package cn.autumnorange.app.common.provider.queue;
//
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback;
//import org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback;
//import org.springframework.amqp.rabbit.support.CorrelationData;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.MessageHeaders;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
////https://blog.csdn.net/maomao1983zy/article/details/119779800
////https://blog.csdn.net/aiwangtingyun/article/details/124009590
//@Slf4j
//@Component
//public class RabbitSender {
//
//    //自动注入RabbitTemplate模板类
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    //回调函数: confirm确认
//    final ConfirmCallback confirmCallback = new ConfirmCallback() {
//        @Override
//        public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//            log.info("correlationData: " + correlationData);
//            log.info("ack: " + ack);
//            if(!ack){
//                log.error("异常处理....");
//            }
//        }
//    };
//
//    //回调函数: return返回
//    final ReturnCallback returnCallback = new ReturnCallback() {
//        @Override
//        public void returnedMessage(org.springframework.amqp.core.Message message, int replyCode, String replyText,
//                                    String exchange, String routingKey) {
//            log.info("return exchange: " + exchange + ", routingKey: "
//                    + routingKey + ", replyCode: " + replyCode + ", replyText: " + replyText);
//        }
//    };
//
//    //发送消息方法调用: 构建Message消息
//    public void send(Object message, Map<String, Object> properties) throws Exception {
//        MessageHeaders mhs = new MessageHeaders(properties);
//        Message msg = MessageBuilder.createMessage(message, mhs);
//        rabbitTemplate.setConfirmCallback(confirmCallback);
//        rabbitTemplate.setReturnCallback(returnCallback);
//        //id + 时间戳 全局唯一
//        CorrelationData correlationData = new CorrelationData("1234567890");
//        rabbitTemplate.convertAndSend("exchange-1", "springboot.abc", msg, correlationData);
//    }
//
//    //发送消息方法调用: 构建自定义对象消息
//    public void sendOrder(Order order) throws Exception {
//        rabbitTemplate.setConfirmCallback(confirmCallback);
//        rabbitTemplate.setReturnCallback(returnCallback);
//        //id + 时间戳 全局唯一
//        CorrelationData correlationData = new CorrelationData("0987654321");
//        rabbitTemplate.convertAndSend("exchange-2", "springboot.def", order, correlationData);
//    }
//
//}
